#!/usr/bin/env bash
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config"
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_BASE_PATH/common/functions"
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"

service-links-cmd() {
  #E list all apps linked to the 'lolipop' $PLUGIN_COMMAND_PREFIX service.
  #E dokku $PLUGIN_COMMAND_PREFIX:links lolipop
  #A service, service to run command against
  declare desc="list all apps linked to the $PLUGIN_SERVICE service"
  local cmd="$PLUGIN_COMMAND_PREFIX:links" argv=("$@")
  [[ ${argv[0]} == "$cmd" ]] && shift 1
  declare SERVICE="$1"
  local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"
  local LINKS_FILE="$SERVICE_ROOT/LINKS"

  [[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a valid name for the service"
  verify_service_name "$SERVICE"
  service_links "$SERVICE"
}

service-links-cmd "$@"
